const tokens = {
  admin: {
    token: 'admin-token',
  },
  editor: {
    token: 'editor-token',
  },
};

const users = {
  'admin-token': {
    roles: ['admin'],
    introduction: 'I am a super administrator',
    avatar:
      'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin',
  },
  // 'editor-token': {
  //   roles: ['editor'],
  //   introduction: 'I am an editor',
  //   avatar:
  //     'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
  //   name: 'Normal Editor'
  // }
};

export default [
  // user login
  {
    url: '/api/admin/login',
    type: 'post',
    response: config => {
      const { username } = config.body;
      const token = tokens[username];

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: 'Account and password are incorrect.',
        };
      }

      return {
        code: 0,
        data: users,
      };
    },
  },

  // get user info
  {
    url: '/vue-admin-template/user/info.*',
    type: 'get',
    response: config => {
      const { token } = config.query;
      const info = users[token];

      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.',
        };
      }

      return {
        code: 20000,
        data: info,
      };
    },
  },

  // user logout
  {
    url: '/vue-admin-template/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success',
      };
    },
  },
  // user logout
  {
    url: '/api/accounts/me',
    type: 'get',
    response: _ => {
      return {
        'id': '1243097290344984577',
        'username': 'test',
        'role': 'ROLE_SUPERMAN',
        'createTime': '2011‐10‐05T14:48:00Z',
        'updateTime': '2011‐10‐05T14:48:00Z',
        'user': {
          'id': '21256833219',
          'displayName': 'test',
          'thirdPartyId': '1232445',
          'sourceId': '1232445',
          'org': [{
            'id': '123123',
            'name': '安全部门',
            'remark': '北信源-安全部门',
          }],
        },
        'customRole': {
          'name': '人事管理员',
          'pattern': ['121', '13', '14', '153', '151', '152'],
        },
      };
    },
  },
  {
    url: '/api/custom-roles',
    type: 'get',
    response: _ => {
      return [
        {
          'id': '1',
          'name': '人事管理员',
          'pattern': ' id1,id2,id3',
          'description': 'description',
        },
        {
          'id': '11',
          'name': '人事管理员2',
          'pattern': ' id1,id2,id3',
          'description': 'description',
        },
      ];
      // return {
      //   'id': '1',
      //   'name': '人事管理员',
      //   'pattern': '1231231,123123,123,2,3',
      //   'description': 'description',
      // };
    },
  },
  {
    url: '/api/user',
    type: 'get',
    response: _ => {
      return [
        {
          'id': '123345',
          'sourceId': '12344',
          'displayName': '',
          'version': '152',
          'dirty': true,
          'thirdPartyId': '0',
          'createTime': '2011‐10‐05T14:48:00Z',
          'updateTime': '2011‐10‐05T14:48:00Z',
          'account': '',
          'enterpriseId': '1',
          'birthday': '',
          'entExtend': '',
          'portraitUrl': '',
          'sdkId': '',
          'roleId': 0,
          'sex': 1,
          'orgId': '',
          'realName': '',
          'phoneNums': '',
          'emails': '',
          'firstPinYin': 'F',
        },
      ];
    },
  }, {
    url: '/api/accounts',
    type: 'get',
    response: _ => {
      return [
        {
          'id': '1243097290344984577',
          'username': 'test',
          'role': 'ROLE_USER',
          'createTime': '2011‐10‐05T14:48:00Z',
          'updateTime': '2011‐10‐05T14:48:00Z',
          'user': {
            'userId': '21256833219',
            'displayName': 'test',
          },
          'customRole': {
            'id': '1123',
            'name': '人事管理员',
            'pattern': 'id1,id2,id3',
          },
        },
      ];
    },
  },
  {
    url: '/api/thirdparties/',
    type: 'get',
    response: _ => {
      return [
        {
          'id': '1',
          'name': 'dood',
          'appId': '21256826272',
          'appSecret': 'f4OwRtkumB9PKKO6Uacy6GviDi53WgjEP2Pjvu6e8GIt',
          'appUrl': 'http://bxy.linkdood.cn:10077/platform/api2',
          'accessType': ' userId ',
        },
        {
          'id': '12',
          'name': 'dood1',
          'appId': '21256826272',
          'appSecret': 'f4OwRtkumB9PKKO6Uacy6GviDi53WgjEP2Pjvu6e8GIt',
          'appUrl': 'http://bxy.linkdood.cn:10077/platform/api2',
          'accessType': ' userId ',
        },
      ];
    },
  },
];
